package com.householdregister.people.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.householdregister.common.utils.poi.ExcelUtil;
import com.householdregister.people.domain.People;
import com.householdregister.people.service.IPeopleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.householdregister.common.annotation.Log;
import com.householdregister.common.core.controller.BaseController;
import com.householdregister.common.core.domain.AjaxResult;
import com.householdregister.common.enums.BusinessType;
import com.householdregister.common.core.page.TableDataInfo;

/**
 * 人员管理Controller
 * 
 * @author zyj
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/people/people")
public class PeopleController extends BaseController
{
    @Autowired
    private IPeopleService peopleService;

    /**
     * 查询人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('people:people:list')")
    @GetMapping("/list")
    public TableDataInfo list(People people)
    {
        startPage();
        List<People> list = peopleService.selectPeopleList(people);
        return getDataTable(list);
    }

    /**
     * 导出人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('people:people:export')")
    @Log(title = "人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, People people)
    {
        List<People> list = peopleService.selectPeopleList(people);
        ExcelUtil<People> util = new ExcelUtil<People>(People.class);
        util.exportExcel(response, list, "人员管理数据");
    }

    /**
     * 获取人员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('people:people:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(peopleService.selectPeopleById(id));
    }

    /**
     * 新增人员管理
     */
    @PreAuthorize("@ss.hasPermi('people:people:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody People people)
    {
        return toAjax(peopleService.insertPeople(people));
    }

    /**
     * 修改人员管理
     */
    @PreAuthorize("@ss.hasPermi('people:people:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody People people)
    {
        return toAjax(peopleService.updatePeople(people));
    }

    /**
     * 删除人员管理
     */
    @PreAuthorize("@ss.hasPermi('people:people:remove')")
    @Log(title = "人员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(peopleService.deletePeopleByIds(ids));
    }

    /**
     * 迁出
     */
    @PreAuthorize("@ss.hasPermi('people:people:remove')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PostMapping("/out")
    public AjaxResult out(@RequestBody People people)
    {
        return toAjax(peopleService.out(people));
    }

    /**
     * 查询人口总数
     * @return
     */
    @GetMapping("/getPeopleCount")
    public AjaxResult selectCountPeople(){
        return AjaxResult.success(peopleService.selectCountPeople());
    }


    /**
     * 查询最近七天迁入迁出数据
     * @return
     */
    @GetMapping("/selectCategroyCount")
    public AjaxResult selectCategroyCount(){
        return AjaxResult.success(peopleService.selectCategroyCount());
    }

    /**
     * 查询最近七天迁入迁出数据
     * @return
     */
    @GetMapping("/selectEducationLevelCount")
    public AjaxResult selectEducationLevelCount(){
        return AjaxResult.success(peopleService.selectEducationLevelCount());
    }
    /**
     * 查询男女数量
     * @return
     */
    @GetMapping("/selectSexCount")
    public AjaxResult selectSexCount(){
        return AjaxResult.success(peopleService.selectSexCount());
    }

    /**
     * 获取最近7天操作人数
     * @return
     */
    @GetMapping("/selectCountByDate")
    public AjaxResult selectCountByDate(){
        return AjaxResult.success(peopleService.selectCountByDate());
    }

}
